
import { mobxState } from "@/data";
import getUserPermission from "./getPromession";
import { loadRouter } from "@/router";
import loadTabs from "@/components/tabs/loadTabs";

/**
 * @description 重新载入用户的路由权限 按钮权限 （当管理员修改了用户权限后，用户端需要刷新浏览器或者重新登录才可生效）
 */
const reloadUserPermission = () => {
    if (sessionStorage.token) {
        const userInfo = JSON.parse(sessionStorage.userInfo);
        getUserPermission(userInfo.userId).then(data => {
            mobxState.updatePermissionList(data.permissionList);
            sessionStorage.setItem("routes", JSON.stringify(data.menus))
            mobxState.updatePermissionList(data.permissionList);
            loadRouter({ routerList: data.menus });
            loadTabs();
        })

    }
}
export default reloadUserPermission